<template>
  <i class="icon iconfont icon-zhaoxiang" @click="chooseAct">
    <my-photo ref="my-photo"/>
  </i>

</template>

<script>
import Vue from 'vue'
import MyPhoto from './MyPhoto'

export default {
  name: 'GetProductNameByImage',
  components: {MyPhoto},
  props:{
    shopId:Number
  },
  data: function () {
    return {
      currCamera: null,
    }
  },
  beforeDestroy () {
    // this.closeCamera()
  },
  methods: {
    chooseAct: function () {
      let $this = this
      $this.$refs['my-photo'].chooseAct(function(filePath){
        $this.uploadAndParseFile(filePath,function (res) {
          // plus.nativeUI.alert('上传成功:' + res)
          if (res.data && res.data.productStockIdList && res.data.productStockIdList.length>0){
            localStorage.setItem('SearchProductStockIdList', JSON.stringify(res.data.productStockIdList))
            localStorage.setItem('SearchProductImageUrl', res.data.url)
            var queryParams={
              type: 'image'
            }
            if ($this.$props.shopId && $this.$props.shopId>0){
              queryParams.shopId=$this.$props.shopId
            }
            $this.$router.push({
              name: 'SearchResult',
              query: queryParams
            })
          }else{
            plus.nativeUI.toast('上传成功: '+res.message)
          }
        },$this.UploadFileFroSearchImageUrl)
      })
    },
  }
}
</script>

<style scoped>

</style>
